package com.yc.ioc.bean3_ioc_factorybean;

import com.yc.ioc.bean3_ioc_factorybean.other.Banana;
import com.yc.ioc.bean3_ioc_factorybean.other.Fruit;
import com.yc.ioc.bean3_ioc_factorybean.other.Grape;
import org.springframework.beans.factory.FactoryBean;

import java.util.Random;

/**
 * @author zwei
 * @create 2024-07-28 16:59
 */
public class FruitFactoryBean implements FactoryBean<Fruit> {
    public FruitFactoryBean(){
        System.out.println("水果工厂的构造方法");
    }


    @Override
    public Fruit getObject() throws Exception {
        Random r=new Random();
        if (r.nextInt(2)==0){
            return new Banana();
        }else {
            return new Grape();
        }
    }

    @Override
    public Class<?> getObjectType() {
        return Fruit.class;
    }
}
